//
//  AFNetworkHandler.m
//  Go Go Buy
//
//  Created by dlios on 15-7-14.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "AFNetworkHandler.h"
@implementation AFNetworkHandler
+ (void)GETWithAFNByURL:(NSString *)urlStr completion:(void (^)(id))block
{
    if (![urlStr isEqual:[NSNull null]]) {
        NSString *str = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        
        AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
        
        manager.responseSerializer = [AFCompoundResponseSerializer serializer];
        
        [manager.responseSerializer setAcceptableContentTypes:[NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", @"text/html", @"text/css", @"text/plain", nil]];
        
        [manager GET:str parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
            //请求成功执行的地方
            //responseObject返回数据为NSData;
            if (responseObject) {
                //如果返回数据不为空 则开始JSON解析
                id result = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
                //通过block回调数据
                block(result);
            } else {
                NSLog(@"返回数据为空, 请检查");
            }
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            //请求失败
            NSLog(@"请求失败: %@", error);
        }];
   }
   

}

@end
